package sf.database.util;

import java.sql.Types;

public class JdbcUtils {
    /**
     * 判断是否是数字类型
     * Check whether the given SQL type is numeric.
     * @param sqlType the SQL type to be checked
     * @return whether the type is numeric
     */
    public static boolean isNumeric(int sqlType) {
        return (Types.BIT == sqlType || Types.BIGINT == sqlType || Types.DECIMAL == sqlType ||
                Types.DOUBLE == sqlType || Types.FLOAT == sqlType || Types.INTEGER == sqlType ||
                Types.NUMERIC == sqlType || Types.REAL == sqlType || Types.SMALLINT == sqlType ||
                Types.TINYINT == sqlType);
    }

    /**
     * 判断是否是字符串类型
     * @param sqlType
     * @return
     */
    public static boolean isString(int sqlType) {
        boolean isString = false;
        switch (sqlType) {
            case Types.CHAR:
            case Types.VARCHAR:
            case Types.LONGVARCHAR:
            case Types.ROWID:
            case Types.NCHAR:
            case Types.NVARCHAR:
            case Types.LONGNVARCHAR:
            case Types.NCLOB:
            case Types.CLOB:
                isString = true;
                break;
            default:
                break;
        }
        return isString;
    }

    /**
     * 判断是否是字节数组类型
     * @param sqlType
     * @return
     */
    public static boolean isByteArray(int sqlType) {
        boolean isByteArray = false;
        switch (sqlType) {
            case Types.BINARY:
            case Types.VARBINARY:
            case Types.LONGVARBINARY:
            case Types.BLOB:
                isByteArray = true;
                break;
            default:
                break;
        }
        return isByteArray;
    }
}
